﻿using Samurai.Validation.Specs.StaticMocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Samurai.Wakizashi.Validation.Validators;

namespace Samurai.Validation.Specs
{
    [TestClass]
    public class DomainValidator_Specification
    {
        [TestMethod]
        public void Executes_custom_validation_against_domain_target()
        {
            var customer = new Customer{Age = 85};

            var v = new DomainValidator<Customer>();
            v.SetValidationLogic(c=>
                                     {
                                         if (c.Age > 70)
                                             v.Result.InvalidProperties.Add("Age", new[] {"Customer is too old!"});
                                     });
            v.Validate(customer);

            var failedAge = v.Result.InvalidProperties.ContainsKey("Age");
            customer.Age = 30;
            v.Validate(customer);
            var passedAge = !v.Result.InvalidProperties.ContainsKey("Age");

            Assert.IsTrue(failedAge && passedAge);
        }
    }
}
